﻿
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>中国中铁工程设计资讯集团生产调度指挥系统</title>
    <link href="./index.css" rel="stylesheet">
    <link href="./loading.css" rel="stylesheet">
</head>

<body>
    <div id="content-wrapper" class="content-wrapper" style="padding:10px;display:none;">
        <div class="content">
            <div class="pure-g">
                <div class="pure-u-1">
                    <a href="#"><img width="480" height="40" src="./logo.png" /></a>
                </div>
            </div>
            <br>
            <div class="pure-g">
                <div class="pure-u-1-2">
                    <legend>待处理的工作</legend>
                </div>
                <div class="pure-u-1-2">
                    <legend style="float:right">
                        <a href="#"  id="sysgo" target="_blank">进入系统</a>
                    </legend>
                </div>
            </div>
            <br>
            <div class="pure-g">
                <div class="pure-u-1">
                    <table class="pure-table pure-table-horizontal pure-table-striped" style="width: 100%;">
                        <thead>
                            <tr style="font-size: 16px">
                                <th>#</th>
                                <th>名称</th>
                                <th>业务操作</th>
                            </tr>
                        </thead>

                        <tbody id="table">
                            
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>


    <div id="loading" class="spinner">
        <div class="spinner-container container1">
            <div class="circle1"></div>
            <div class="circle2"></div>
            <div class="circle3"></div>
            <div class="circle4"></div>
        </div>
        <div class="spinner-container container2">
            <div class="circle1"></div>
            <div class="circle2"></div>
            <div class="circle3"></div>
            <div class="circle4"></div>
        </div>
        <div class="spinner-container container3">
            <div class="circle1"></div>
            <div class="circle2"></div>
            <div class="circle3"></div>
            <div class="circle4"></div>
        </div>
    </div>

    <div id="spinner-text" class="spinner-text">
        <div>正在获取待处理事务</div>
    </div>

    <script>
    	var username=getParam('uname');
        var tools = {}
	

        //格式化参数
        tools.formatParams = function (data) {
        	if(typeof(data)=="undefined"){ 
        		return "";
        	}
            var arr = [];
            for (var name in data) {
                arr.push(encodeURIComponent(name) + "=" + encodeURIComponent(data[name]));
            }
            arr.push(("v=" + Math.random()).replace("."));
            return arr.join("&");
        }

        tools.ajax = function (options) {
            options = options || {};
            options.type = (options.type || "GET").toUpperCase();
            options.dataType = options.dataType || "json";
            var params = tools.formatParams(options.data);

            //创建 - 非IE6 - 第一步
            if (window.XMLHttpRequest) {
                var xhr = new XMLHttpRequest();
            } else { //IE6及其以下版本浏览器
                var xhr = new ActiveXObject('Microsoft.XMLHTTP');
            }

            //接收 - 第三步
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                    var status = xhr.status;
                    if (status >= 200 && status < 300) {
                        options.success && options.success(xhr.responseText, xhr.responseXML);
                    } else {
                        options.fail && options.fail(status);
                    }
                }
            }

            //连接 和 发送 - 第二步
            if (options.type == "GET") {
                xhr.open("GET", options.url + "?" + params, true);
                xhr.send(null);
            } else if (options.type == "POST") {
                xhr.open("POST", options.url, true);
                //设置表单提交时的内容类型
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xhr.send(params);
            }
        }

        function getParam(name)
        {
             new RegExp("(^|&)"+name+"=([^&]*)").exec(window.location.search.substr(1));
             return RegExp.$2
        }
        
        window.onload=function(){
            window.external.ShowMessage('rewindow');
        	if(username!=''&&username!=null){
        		   tools.ajax({
                       url: 'gosys?mname='+username,
                       type: 'GET',
                       dataType: 'json',
                       success: function (response, xml) {
                           document.getElementById('sysgo').href = response;

                       },
                       fail: function (status) {
                           alert("服务器错误")
                       }
                   })
        	}
        	
        }

        var tasknum=0;

        function getData() {

                tools.ajax({
                    url: 'rts?mname='+username,
                    type: 'POST',
                    dataType: 'json',
                    success: function (response, xml) {
                        var result = JSON.parse(response);
                        var tpl = '';
                        var showtpl=''
                        if(tasknum==0){
                            tasknum=result.length;
                        }else if(tasknum>result.length){
                            tasknum=result.length;
                        }else if(tasknum<result.length){
                            tasknum=result.length;
                            window.external.showtask();
                        }
                        document.getElementById('table').innerHTML="";
                        for (var i = 0; i < result.length; i++) {
                            if(result[i].messageType=='link_msg'){
                                tpl = tpl + '<tr><td>' + (i + 1) + '</td> <td><a href="' + (result[i].requestUrld) +  '" target="_blank">' + (result[i].name) + '</a></td> <td>' + (result[i].status) + '</td> </tr>';
                            }else{
                                showtpl = showtpl + '<tr><td>' + (i + 1) + '</td> <td><a href="' + (result[i].requestUrld) +  '" target="_blank">' + (result[i].name) + '</a></td> <td>' + (result[i].status) + '</td> </tr>';
                            }

                        }
                        document.getElementById('table').innerHTML = tpl;
                        document.getElementById('showtable').innerHTML=showtpl
                        document.getElementById('content-wrapper').style.display = 'block';
                        document.getElementById('loading').style.display = 'none'
                        document.getElementById('spinner-text').style.display = 'none'

                    },
                    fail: function (status) {
                        console.info(status)
                    }
                })
        }

        window.setInterval("getData()",1000*10);
    </script>
</body>

</html>